<?php if ($this->mode == INSERT_MODE): ?>
    <?php $action = $this->url(); ?>
    <?php $title = 'New Port' ?>
<?php else: ?>
    <?php $action = $this->url(array('action' => 'editport')); ?>
    <?php $title = 'Edit Port' ?>
<?php endif; ?>

<h1>
    <?php echo $title ?>
</h1>

<form method='POST' action='<?php echo $action ?>' id='newport'>
    <div class='wrap-content'>
        <label>
            Port Name
        </label>   
        <div class='content'>                 
            <div class='wrap-input'>
                <input type='text' name='name' value='<?php echo isset($this->port) ? $this->port->name: '' ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'name')) ?>
            </div>
        </div>
    </div>
    <div class='wrap-content'>
        <label>
            Description
        </label>   
        <div class='content'>                 
            <div class='wrap-input'>
                <textarea id='description' name='description' id='description'>
                    <?php echo isset($this->port) ? $this->port->description : '' ?>
                </textarea>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'description')) ?>
            </div>
        </div>
    </div>          
    <div class='wrap-content'>
        <label>
            Location
        </label>   
        <div class='content'> 
            <div id='map-canvas'></div>
        </div>
    </div>
    <div class='wrap-content'>
        <label>
            Latitude
        </label>   
        <div class='content'>                 
            <div class='wrap-input'>
                <input type='text' name='latitude' id='latitude' onkeyup='placeMarker()'  value='<?php echo isset($this->port) ? $this->port->latitude : '' ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'latitude')) ?>
            </div>
        </div>
    </div>                              
    <div class='wrap-content'>
        <label>
            Longitude
        </label>   
        <div class='content'>                 
            <div class='wrap-input'>
                <input type='text' name='longitude' id='longitude' value='<?php echo isset($this->port) ? $this->port->longitude : '' ?>'/>
                <?php echo $this->partial("/_partial/field_error.phtml", array('errors' => $this->errors, 'field' => 'longitude')) ?>
            </div>
            <input type='submit' value='Add New' class='submit-button' onkeyup='placeMarker()'/>
            <a href='<?php echo $this->url(array('action' => 'ports', 'module' => 'admin', 'controller' => 'index')) ?>'>
                <input type='button' value='Cancel' class='submit-button'/>
            </a>
        </div>
    </div>
</form>
<script src="<?php echo $this->baseUrl() ?>/public/js/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
    tinymce.init({
        selector: "#description",
        plugins: [
            "advlist autolink lists link image charmap print preview anchor",
            "searchreplace visualblocks code fullscreen",
            "insertdatetime media table contextmenu paste moxiemanager"
        ],
        toolbar: "insertfile undo redo | styleselect | bold italic forecolor | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
    });
</script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>
<script src='<?php echo $this->baseUrl() ?>/public/js/admin/newport.js'></script>
<script src='http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.min.js'></script>